package com.htgd.gardenexpo.service.impl;

import com.htgd.gardenexpo.entity.CommonResult;
import com.htgd.gardenexpo.entity.GeConDeviceStatus;
import com.htgd.gardenexpo.dao.GeConDeviceStatusMapper;
import com.htgd.gardenexpo.service.IGeConDeviceStatusService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 设备当前状态表 服务实现类
 * </p>
 *
 * @author author
 * @since 2025-04-23
 */
@Service
public class GeConDeviceStatusServiceImpl extends ServiceImpl<GeConDeviceStatusMapper, GeConDeviceStatus> implements IGeConDeviceStatusService {

    @Autowired
    private GeConDeviceStatusMapper geConDeviceStatusMapper;

    @Override
    public CommonResult getStatus(String deviceId) {
        //判断设备是否存在
        boolean exists = lambdaQuery().eq(GeConDeviceStatus::getDeviceId, deviceId).exists();
        if(!exists){
            GeConDeviceStatus geConDeviceStatus = new GeConDeviceStatus();
            geConDeviceStatus.setDeviceId(deviceId);
            geConDeviceStatus.setStatus("1");
            geConDeviceStatusMapper.insert(geConDeviceStatus);
        }
        //查询
        GeConDeviceStatus one = lambdaQuery().eq(GeConDeviceStatus::getDeviceId, deviceId).one();
        return CommonResult.success("查询成功",one.getStatus());
    }
}
